<?php

class ReqtrackHelper extends Helper
{	
	public function buildAssocArray ($array, $field = null, $table = null)
	{
		$tmp = array();
		//$this->afficheArray($array, 0);
		
		foreach ($array as $tab)
			if (is_array($tab))
				$tmp[$tab[$table][$field]] = $tab[$table][$field];
			else
				$tmp[$tab] = $tab;
		
		//$this->afficheArray($tmp, 0);
		return $tmp;
	}
	
	public function buildAssocNumberArray ($array, $field = null, $table = null)
	{
		$tmp = array();
		$i = 1;
		//$this->afficheArray($array, 0);
		
		foreach ($array as $tab)
			if (is_array($tab))
				$tmp[$i++] = $tab[$table][$field];
			else
				$tmp[$i++] = $tab;
		
		//$this->afficheArray($tmp, 0);
		return $tmp;
	}
	
	// Retourne un tableau mis en page
	public function afficheArray ($array, $index = 0)
	{
		echo 'On entre dans afficheArray()<br/>';
		$colors = array ('black', 'blue', 'green', 'red', 'purple', 'brown', 'orange', 'yellow');
		
		foreach ($array as $key => $value)
		{
			for ($i = 0 ; $i < 10 * $index ; ++$i)
				echo '&nbsp;';
			
			if ($index % 2 == 0)
				echo '<strong><font color="'.$colors[$index].'">'.$key.'</font></strong><br>';
			else
				echo '<font color="'.$colors[$index].'">'.$key.'</font><br>';
			
			if (is_array($value))
				$this->AfficheArray($value, $index + 1);
			else
			{
				for ($i = 0 ; $i < 15 * $index ; ++$i)
					echo '&nbsp;';
					
				echo '<font color="'.$colors[$index + 1].'">'.$value.'</font><br>';
			}
		}
	}
	
};

?>